package cn.edu.zust.loginandregisterservice.controller;

import cn.edu.zust.loginandregisterservice.mapper.CompanyClient;
import cn.edu.zust.loginandregisterservice.mapper.UserClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/loginAndRegister")
public class LoginAndRegisterController {
    @Autowired
    CompanyClient companyClient;
    @Autowired
    UserClient userClient;

    @GetMapping("/login/{account}")
    public String login(@PathVariable String account){
        if (account.length() >= 7) {
            String prefix = account.substring(0, 7);
            if ("company".equals(prefix)) {
                return companyClient.getCompanyPasswordByAccount(account);
            }else {
                return userClient.getPasswordByAccount(account);
            }
        }
        return "错误";

    }
}
